﻿//using System.IO;
//using System.Runtime.Serialization.Json;
//using System.Text;
using System.Web.Script.Serialization;

namespace MVCnExt.Util
{
  public static class ExtJsJsonHelper
  {
    public static string ToExtJsJsonReader(this object data, string rootName)
    {
        return data.ToJson(); //string.Format("{{ {0} : {1} }}", rootName, data.ToJson());
    }

    //public static string ToJson(this object data)
    //{
    //  using (var stream = new MemoryStream())
    //  {
    //    new DataContractJsonSerializer(data.GetType()).WriteObject(stream, data);
    //    return Encoding.Default.GetString(stream.ToArray());
    //  }
    //}

    public static string ToJson(this object data)
    {
      var serializer = new JavaScriptSerializer();
      
       
      //string str = "[ { text: 'ExtJS Main', leaf: true }, { text: 'ExtJS Learn', leaf: true },{ text: 'ExtJS Forum', children: [ { text: 'Premium Help', leaf: true }, { text: 'Examples and Extras', leaf: true } ] } ] ";
      return serializer.Serialize(data);
    }
  }
}